home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Other Langs
/
Tickle-4.0 (tcl)
/
src
/
progress.c
< prev
next >
Wrap
Text File
|
1993-11-18
|
6KB
|
284 lines
/*
** This source code was written by Tim Endres
** Email: time@ice.com.
** USMail: 8840 Main Street, Whitmore Lake, MI 48189
**
** Some portions of this application utilize sources
** that are copyrighted by ICE Engineering, Inc., and
** ICE Engineering retains all rights to those sources.
**
** Neither ICE Engineering, Inc., nor Tim Endres,
** warrants this source code for any reason, and neither
** party assumes any responsbility for the use of these
** sources, libraries, or applications. The user of these
** sources and binaries assumes all responsbilities for
** any resulting consequences.
*/
#pragma segment Progress
#include "tickle.h"
#include <OSEvents.h>
typedef void (*PFV)();
WindowPtr progress_window = NULL;
PFV progress_string_func = (PFV)0;
int progress_pos, progress_start, progress_end;
short progress_active = 0, progress_right = 0;
unsigned long progress_tick = 0;
PixPatHandle progress_backpat = NULL;
PixPatHandle progress_progpat = NULL;
void
SPPercentCompleteProc(message, start, end, pos)
char *message;
int start;
int end;
int pos;
{
sprintf( message, "Completed %02d%%...",
( ((pos - start) * 100) / (end - start) ) );
}
void
SProgressCounting(message, start, end, pos)
char *message;
int start;
int end;
int pos;
{
#pragma unused (end)
sprintf(message, "Counting %d files...", (pos - start));
}
void
SProgressCopyFiles(message, start, end, pos)
char *message;
int start;
int end;
int pos;
{
#pragma unused (pos)
sprintf(message, "Copied %d of %d files...",
(progress_pos - progress_start), (end - start));
}
StartProgressWindow(title, start, end, pos, string_func)
char *title; /* Pascal */
int start;
int end;
PFV string_func;
{
Rect myrect;
int progressWProc();
if (progress_window == (WindowPtr)0)
{
SetRect(&myrect, 25, 50, 275, 85);
if (theEnviron.hasColorQD)
{
progress_window = NewCWindow(NULL, &myrect, title, true,
noGrowDocProc, inFront, false, (long)progressWProc);
progress_backpat = GetPixPat(6979);
progress_progpat = GetPixPat(6984);
}
else
{
progress_window = NewWindow(NULL, &myrect, title, true,
noGrowDocProc, inFront, false, (long)progressWProc);
progress_backpat = (PixPatHandle)0;
progress_progpat = (PixPatHandle)0;
}
if (progress_window != (WindowPtr)0)
((WindowPeek) progress_window)->windowKind = progressWKind;
}
progress_start = start;
progress_end = end;
progress_pos = pos;
progress_right = 1;
progress_tick = TickCount() - 1;
progress_string_func = string_func;
}
UpdateProgress(pos)
int pos;
{
Rect myrect;
int need_inval = 0;
if (progress_window != NULL)
{
if (progress_end == -1)
{
if (TickCount() > progress_tick)
need_inval = 1;
}
else if (progress_pos != pos)
{
if (TickCount() > progress_tick)
need_inval = 1;
}
if (pos == -1)
{
progress_pos = progress_end;
need_inval = 1;
}
else
{
progress_pos = pos;
}
if (need_inval)
{
focus(progress_window);
myrect = progress_window->portRect;
InsetRect(&myrect, 4, 4);
myrect.top = myrect.bottom - 12;
InsetRect(&myrect, 1, 1);
InvalRect(&myrect);
myrect = progress_window->portRect;
myrect.bottom = myrect.top + 20;
InsetRect(&myrect, 3, 3);
InvalRect(&myrect);
progressW_update(progress_window);
unfocus();
}
}
}
StopProgressWindow()
{
int progressWProc();
if (progress_window != NULL)
{
DisposeWindow(progress_window);
progress_window = (WindowPtr)0;
}
}
progressWProc(myWindow, myEvent, wAction)
WindowPtr myWindow;
EventRecord *myEvent;
int wAction;
{
#pragma unused (myEvent)
switch (wAction) {
case wContent:
SysBeep(0); /* Need cancel button... */
break;
case wActivate:
progressW_activate(myWindow, (myEvent->modifiers & 0x00000001) != 0);
break;
case wUpdate:
progressW_update(myWindow);
break;
case wClose:
break;
case wKeyDown:
SysBeep(0); /* Need cancel button... */
break;
}
}
progressW_update(myWindow)
WindowPtr myWindow;
{
double percent;
Rect myrect;
char message[256];
focus(myWindow);
BeginUpdate(myWindow);
myrect = myWindow->portRect;
EraseRect(&myrect);
InsetRect(&myrect, 1, 1);
FrameRect(&myrect);
myrect = myWindow->portRect;
InsetRect(&myrect, 4, 4);
myrect.top = myrect.bottom - 12;
FrameRect(&myrect);
InsetRect(&myrect, 1, 1);
if (theEnviron.hasColorQD && progress_backpat != NULL)
FillCRect(&myrect, progress_backpat);
if (progress_end != -1)
{
percent = ((double) progress_pos) /
( (double) progress_end - (double) progress_start );
myrect.right = myrect.left + (int)( percent * (double)(myrect.right - myrect.left) );
progress_tick = TickCount() + 20;
}
else if (TickCount() > progress_tick)
{
if (progress_right)
{
myrect.right = myrect.left + ( (myrect.right - myrect.left) >> 1 );
progress_right = 0;
}
else
{
myrect.left = myrect.right - ( (myrect.right - myrect.left) >> 1 );
progress_right = 1;
}
progress_tick = TickCount() + 45;
}
else
{
myrect.right = myrect.left;
}
if (theEnviron.hasColorQD && progress_backpat != NULL)
FillCRect(&myrect, progress_progpat);
else
FillRect(&myrect, qd.black);
MoveTo(myWindow->portRect.left + 5, myWindow->portRect.top + 15);
if (progress_string_func != (PFV)0)
{
(progress_string_func) (message, progress_start, progress_end, progress_pos);
}
else
{
sprintf(message, "Completed %d of %d...",
progress_pos - progress_start, progress_end - progress_start);
}
c2pstr(message);
TextFont(systemFont); TextSize(12);
DrawString(message);
EndUpdate(myWindow);
unfocus();
}
progressW_activate(myWindow, actflag)
WindowPtr myWindow;
long actflag;
{
#pragma unused (myWindow)
progress_active = actflag;
}